<template>
  <div class="divBox">
    <el-card class="box-card">
      <el-form inline size="small" @submit.native.prevent>
        <el-form-item label="订单状态:">
          <el-select v-model="listPram.status" placeholder="请选择" style="width: 200px;">
            <el-option
                v-for="item in statusList"
                :key="item.id"
                :label="item.data"
                :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="选择时间：">
          <el-date-picker
              v-model="value1"
              @change="handleChange"
              value-format="yyyy-MM-dd" format="yyyy-MM-dd"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              style="width: 220px"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-search" size="mini" type="primary" @click.native="getList">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>

<!--        <el-form-item label="累计券额" style="margin-left:100px;">-->
<!--          {{ totalAmount }}-->
<!--        </el-form-item>-->

      </el-form>
      <el-table :data="listData.list" size="mini"
                :header-cell-style=" {fontWeight:'bold',background:'#f8f8f9',color: '#515a6e',height:'40px'}" border>
        <el-table-column label="ID" prop="id" min-width="40"></el-table-column>
        <el-table-column label="订单号" min-width="150" prop="orderId"/>
        <el-table-column label="商家名称" prop="businessInfo.businessName" min-width="100"/>
<!--        <el-table-column label="活动名称" prop="activityName" min-width="100"/>-->
        <el-table-column label="益联券" min-width="50" prop="orderMoney"/>
        <el-table-column label="用户昵称" min-width="50" prop="userInfo.name"/>
        <el-table-column label="用户手机号" min-width="70" prop="userInfo.phone"/>
        <el-table-column label="用户所在地区" min-width="100" prop="cityAreaName"/>
        <el-table-column label="订单状态" min-width="100" prop="status">
          <template slot-scope="scope">
            <div style="color:#f50d2f;" v-if="scope.row.status===1">待使用</div>
            <div style="color:#038328;" v-if="scope.row.status===2">待评价</div>
            <div style="color:#038328;" v-if="scope.row.status===3">已完成</div>
            <div style="color:#022cff;" v-if="scope.row.status===4">已取消</div>
          </template>
        </el-table-column>
        <el-table-column label="购买时间" prop="createTime" min-width="120"/>
        <el-table-column label="操作" min-width="180" fixed="right" align="center">
          <template slot-scope="scope">
            <!--            <el-button icon="el-icon-edit" v-if="scope.row.status===1" size="mini" type="warning"-->
            <!--                       @click="openEdit(scope.row.id)" v-has-permi="['admin:businessOrder:send']">发送货-->
            <!--            </el-button>-->
            <!--            <el-button icon="el-icon-tickets" v-if="scope.row.status===2 || scope.row.status===3" size="mini" type="success"-->
            <!--                       @click="openShippingInformation(scope.row.id)" v-has-permi="['admin:businessOrder:shippingInformation']">配送信息-->
            <!--            </el-button>-->
            <el-button size="mini" type="primary" @click="openEdit(scope.row.orderId)"
                       >兑换券列表
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
          :current-page="listPram.page"
          :page-sizes="[20,40,60,80,100]"
          layout="total, sizes, prev, pager, next, jumper"
          :total="listData.count"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
      />
    </el-card>
<!--    <el-dialog-->
<!--        :visible.sync="editDialog.show"-->
<!--        :title="'发货'"-->
<!--        destroy-on-close-->
<!--        :close-on-click-modal="false"-->
<!--        width="1200px"-->
<!--        top="80px">-->
<!--      <edit-->
<!--          v-if="editDialog.show"-->
<!--          :id="editDialog.id"-->
<!--          @hideEditDialog="hideEditDialog"-->
<!--          ref="editForm"-->
<!--      />-->
<!--    </el-dialog>-->
    <el-dialog
        :visible.sync="editUserDialog.show"
        :title="editUserDialog.id? '用户详情':'新增'"
        destroy-on-close
        :close-on-click-modal="false"
        width="1000px">
      <userEdit
          v-if="editUserDialog.show"
          :id="editUserDialog.id"
          @hideUserEditDialog="hideUserEditDialog"
          ref="editForm"
      />
    </el-dialog>
  </div>
</template>

<script>
// import edit from './edit.vue'
import { list} from "@/api/consumption";
import {checkPermi} from "@/utils/permission";
import ShippingInformation from "@/views/financial/order/shippingInformation.vue";
import userEdit from "@/views/financial/consumption/userEdit.vue";


export default {
  components: {userEdit, ShippingInformation},
  data() {
    return {
      listData: {list: [], count: 0},
      listPram: {
        page: 0,
        limit: 20,
        businessName: '',
        businessId: ''
      },
      editUserDialog: {
        show: false,
        id: null
      },
      shippingInformationDialog: {
        show: false,
        id: null
      },
      totalAmount: 0,
      tableLoading: false,
      statusList: [{id: 1, data: '待使用'}, {id: 2, data: '待评价'}, {id: 3, data: '已完成 '}, {
        id: 4,
        data: '已取消 '
      }],
      merchantOptions: [],
      value1: '',
    }
  },
  mounted() {
    this.getList()
    this.getMerchantOptions()
  },
  methods: {
    handleChange(value) {
      if (Array.isArray(value) && value.length === 2) {
        this.listPram.beginTime = value[0];
        this.listPram.endTime = value[1];
      }
    },
    checkPermi,
    getList() {
      this.tableLoading = true
      list(this.listPram).then(res => {
        this.tableLoading = false;
        this.listData = res;
      })
      orderCumulativeVoucherAmountAPI(this.listPram).then(res => {
        this.totalAmount = res
      })

    },
    getMerchantOptions() {
      getMerchantOptionsApi().then(res => {
        this.merchantOptions = res
      })
    },
    openEdit(id = null) {
      this.editUserDialog.id = id;
      this.editUserDialog.show = true
    },
    openShippingInformation(id = null) {
      this.shippingInformationDialog.id = id;
      this.shippingInformationDialog.show = true
    },
    handlerDelete(id) {
      this.$confirm('确认删除该数据吗？').then(() => {
        const loading = this.$loading({text: '删除中', background: 'rgba(255,255,255,.5)'})
        deleteRow(id).then(() => {
          this.$message.success('删除成功')
          this.getList()
        }).finally(() => {
          loading.close()
        })
      })
    },
    hideUserEditDialog() {
      this.editUserDialog.show = false
      this.getList()
    },
    handleSizeChange(val) {
      this.listPram.limit = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.listPram.page = val
      this.getList()
    },
    resetQuery() {
      this.listPram.status = '';
      this.listPram.businessId = '';
      this.value1 = '';
      this.listPram.beginTime = '';
      this.listPram.endTime = '';
      this.getList()
    }
  }
}
</script>

<style scoped lang="scss">
.my-autocomplete {
  li {
    line-height: normal;
    padding: 7px;

    .name {
      text-overflow: ellipsis;
      overflow: hidden;
    }

    .addr {
      font-size: 12px;
      color: #b4b4b4;
    }

    .highlighted .addr {
      color: #ddd;
    }
  }
}
</style>
